// pages/Orderdetails/Orderdetails.js
var Api = require("../../../api/method.js");
var Utils = require("../../../utils/util.js");
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '2019-01-01 13:37',
    disabled: false,//设置是否能点击 false可以 true不能点击
    startDate: '2000-01-01 12:37',
    endDate: '2099-03-12 12:38',
    placeholder: '请选择时间',
    page: 1,
    contentlist: [],
    orderList:[],
    max_count: '20',  //根据后台每页的数据设定
    hasMoreData: '',   //是否有更多数据文字
    searchVal:"",
    pageNo:1,
    searchimg:true
  },
  //搜索接口
  search:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    // console.log(that)
    let list = {
      pageNo: that.data.pageNo,
      branchId: wx.getStorageSync("user").branchId,
      pageSize: 20,
      beginTime: that.data.date,
      endTime: that.data.date1,
      orderId: that.data.searchVal,
      transactionId: that.data.searchVal
    };
    console.log(list)
    Api.branchorder(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 1) {
        if (that.data.page == 1) {
          let ar = res.data.data;
          for (var i = 0; i < ar.length; i++) {
            ar[i].createdAt = Utils.chinesetime((ar[i]).createdAt, 'Y-M-D h:m')
          }
          console.log(ar)
          that.setData({
            orderList: ar
          })
        } else {
          that.setData({
            orderList: that.data.orderList.concat(ar)
          })
        }
        if (res.data.data == "" && that.data.page != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: "none",
            duration: 1500
          })
        }
      }
      wx.hideLoading();
    })

  },
  //input搜索
  searchContent:function(e){
    console.log(e)
    if (e.detail.value != ""){
      this.setData({
        searchVal: e.detail.value,
        searchimg:false
      })
      console.log(this.data.searchVal)
    this.search()
    // this.setData({
    //   searchVal:""
     
    // })
    }else{
      this.branchorderList();
      this.setData({
        searchimg:true
      })
    }
  },
  branchorderList:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      branchId: wx.getStorageSync("user").branchId,
      pageNo:that.data.page,
      pageSize :20
    }
    Api.branchorder(list,function(err,res){
      console.log(res.data)
      if(res.data.code == 1){
        if(that.data.page == 1){
          let ar = res.data.data;
          for(var i=0;i<ar.length;i++){
            ar[i].createdAt = Utils.chinesetime((ar[i]).createdAt, 'Y-M-D h:m')
          }
          // console.log(ar)
          that.setData({
            orderList:ar
          })
        }else{
          that.setData({
            orderList: that.data.orderList.concat(ar)
          })
        }
        if (res.data.data == "" && that.data.page != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: "none",
            duration: 1500
          })
        }
      }
      wx.hideLoading();
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // that.getdata(that.data.page, that.data.max_count);   //调用
    that.branchorderList();
  },
  // 选择日期时间
  onPickerChange: function (e) {
    console.log(e.detail);
    this.setData({
      date: e.detail.dateString
    })
  },
  onPickerChange1: function (e) {
    console.log(e.detail);
    this.setData({
      date1: e.detail.dateString
    })
    this.search();
  },
  //跳转页面详情
  Details: function (e) {
    wx.navigateTo({
      url: "/pages/branch/Details/Details?id=" + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // //加载本页面的tabBar样式
    // app.editTabBar1();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    that.getdata(1, that.data.max_count);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    that.getdata(that.data.page, that.data.max_count);
    that.setData({
      page: that.data.page + 1
    });
    that.branchorderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})